<template>
  <div>
    <el-button @click="closeDrawer()" size="small" type="primary">导入模板下载</el-button>
    <div style="margin:20px 0"></div>
    <importFile :title="'导入'" :actionUrl="`${uploadPrefix}/api/cmscloud.wholesales/retailSetDealer/dealerImportFromExcel`" :params="params" @close="closeHandler" />

    <div style="height:47px;"></div>
  </div>
</template>
<script>
import { downloadDealer } from '@/api/omSale/vehicleParameters/PlanOrderTime/index.js';
import { downloadUrl, exportExcelFile } from '@/utils';
import config from '@/assets/js/config';
import moment from 'moment';
export default {
  props: ['rowData'],
  data() {
    return {
      uploadPrefix: config.uploadUrl, // 附件上传前缀
      fetchParams: {},
      params: {
        setId: this.rowData.setId
      },
      form: {
        fileList: []
      },
      fetchApi: () => {}
    };
  },

  created() {
    console.log('init=>' + this.rowData);
    console.log('init url=>' + this.uploadPrefix);
  },
  methods: {
    closeDrawer(type) {
      this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          // downloadUrl(`/api/cmscloud.wholesales/retailSetDealer/export`, '经销商导入模板');
          let res = await downloadDealer();
          exportExcelFile(res.data, '经销商导入模板');
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    closeHandler(val) {
      console.log(val);
      if (val && val.length > 0) {
        this.form.fileList = val;
        this.$emit('close', val);
      } else {
        this.$emit('close', []);
      }
    }
  }
};
</script>
